home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / dpmigcc5.zip / RSX / SOURCE / FPU-EMU / CRT0FPU.S < prev    next >
Text File  |  1994-05-27  |  4KB  |  219 lines

  1. /* copro struct */
  2.  
  3. #define i_orgeip    _info
  4. #define i_retsys    _info+4
  5. #define i_ebx        _info+8
  6. #define i_ecx        _info+12
  7. #define i_edx        _info+16
  8. #define i_esi        _info+20
  9. #define i_edi        _info+24
  10. #define i_ebp        _info+28
  11. #define i_eax        _info+32
  12. #define i_ds        _info+36
  13. #define i_es        _info+40
  14. #define i_fs        _info+44
  15. #define i_gs        _info+48
  16. #define i_orgeax    _info+52
  17. #define i_eip        _info+56
  18. #define i_cs        _info+60
  19. #define i_eflags    _info+64
  20. #define i_esp        _info+68
  21. #define i_ss        _info+72
  22.  
  23. #define i_vm86_es   _info+76
  24. #define i_vm86_ds   _info+80
  25. #define i_vm86_fs   _info+84
  26. #define i_vm86_gs   _info+88
  27.  
  28.  
  29.     .globl _fpu_entry
  30.     .globl _back_to_prg
  31.     .globl _debugged
  32.     .globl _used_math
  33.     .globl _raise
  34.  
  35.     .text
  36.  
  37. /* called from extender: 1. init exception ; 2. change mathe state */
  38. /* gs = emu data seg */
  39.  
  40. _fpu_entry:
  41.     cmpl    $0x12345678,%eax    /* init call ? */
  42.     jz    L10
  43.     movl    %edx, %gs:_debugged    /* debugged>0 : don't lookahead */
  44.     movl    %ecx, %gs:_used_math    /* used_math>0: don't init */
  45.     lret
  46.  
  47.  
  48. /* ! can't use movl %eax,gs:xx (bug ??) */
  49.  
  50.  
  51. _emu_selector:
  52.     .long 0
  53.  
  54.     .align 2,144
  55. /* init exception vector 7 */
  56. L10:
  57.     movw    %gs, %cx
  58.     movw    %cx, %gs:_emu_selector    /* save dataseg in code */
  59.     movw    %edx, %gs:emu_esp    /* save dataseg in code */
  60.  
  61.     movw    %cs,%cx         /* cx:edx exception-handler */
  62.     movl    $_exception7,%edx
  63.     movw    $0x203,%ax
  64.     movw    $0x7,%bx        /* 387 exception */
  65.     int    $0x31
  66.     jnc    1f
  67.     movl    $0,%eax         /* 0 = error */
  68.     jmp    2f
  69. 1:
  70.     movl    $_copro , %eax        /* return coprostruct */
  71. 2:
  72.     lret
  73.  
  74.  
  75.  
  76. /* stack after exception :
  77. *
  78. *        0  = DPMIeip,
  79. *        4  = DPMIcs,
  80. *        8  = error code,
  81. *        12 = eip,
  82. *        16 = cs,
  83. *        20 = eflags,
  84. *        24 = esp,
  85. *        28 = ss
  86. */
  87.  
  88. #define EIP    12
  89. #define CS    16
  90. #define EFLAGS    20
  91. #define ESP    24
  92. #define SS    28
  93.  
  94. /* entry for emulation :
  95. **    ds,es,fs,gs = user_prg_ds
  96. **    stack = dpmi-server ss,esp
  97. */
  98.  
  99.     .align 2,144
  100. _exception7:
  101.     pushl    %cs:_emu_selector    /* load datasegment */
  102.     popl    %ds
  103.  
  104.     movw    %es, i_ds
  105.     movw    %es, i_es
  106.     movw    %fs, i_fs
  107.     movl    %eax, i_eax
  108.     movl    %eax, i_orgeax
  109.     movl    %ebx, i_ebx
  110.     movl    %ecx, i_ecx
  111.     movl    %edx, i_edx
  112.     movl    %esi, i_esi
  113.     movl    %edi, i_edi
  114.     movl    %ebp, i_ebp
  115.  
  116.  
  117.     /* save regs on dpmi stack */
  118.     movl    EIP(%esp), %eax
  119.     movl    %eax, i_orgeip
  120.     movl    %eax, i_eip
  121.     movl    CS(%esp), %eax
  122.     movl    %eax, i_cs
  123.     movl    EFLAGS(%esp), %eax
  124.     andl    $0xFFFEFFFF,%eax    /* clear resume flag */
  125.     movl    %eax, i_eflags
  126.     andl    $0xFFFFFEFF,%eax    /* clear step flag */
  127.     orl    $0x200,%eax        /* set iflag */
  128.     movl    %eax, EFLAGS(%esp)    /* save back */
  129.     movl    ESP(%esp), %eax
  130.     movl    %eax, i_esp
  131.     movl    SS(%esp), %eax
  132.     movl    %eax, i_ss
  133.  
  134.     /* prepare stack frame for lret */
  135.     movw    %ds, %ax
  136.     movw    %ax, SS(%esp)
  137.     movl    emu_esp, %eax
  138.     movl    %eax, ESP(%esp)
  139.     movw    %cs, %ax
  140.     movw    %ax, CS(%esp)
  141.     movl    $emulate, %eax
  142.     movl    %eax, EIP(%esp)
  143.  
  144.     /* resore eax (not necessary?) */
  145.     movl    i_eax, %eax
  146.     pushl    %es
  147.     popl    %ds
  148.  
  149.     lret
  150.     /* back to dpmi-handler */
  151.     /* jmp to our handler cs:emulate */
  152.  
  153.  
  154. /* called from DPMI-server after return from exception7 */
  155. /* cs:eip and ss:esp are ok */
  156.  
  157.     .align 2,144
  158. emulate:
  159.     movw    %ss, %ax    /* set ds,es */
  160.     movw    %ax, %ds
  161.     movw    %ax, %es
  162.     pushl    $_info
  163.     call    _math_emulate
  164. _back_to_prg:
  165.     movl    i_eax,%eax
  166.     movl    i_ebx,%ebx
  167.     movl    i_ecx,%ecx
  168.     movl    i_edx,%edx
  169.     movl    i_esi,%esi
  170.     movl    i_edi,%edi
  171.     movl    i_ebp,%ebp
  172.     movw    i_es,%es
  173.     movw    i_fs,%fs
  174.  
  175.     movw    i_ss,%ss    /* change stack to user */
  176.     movl    i_esp,%esp
  177.  
  178.     pushl    i_eflags
  179.     pushl    i_cs
  180.     pushl    i_eip
  181.     movw    i_ds,%ds
  182.     iret
  183.  
  184. _abort_emu:
  185. _raise:
  186.     movw $0x7f0e,%ax
  187.     movw $0x8 ,%cx
  188.     int $0x21
  189.  
  190.     movw $0x4cff,%ax
  191.     int $0x21
  192.     ret
  193.  
  194.  
  195.  
  196.     .data
  197.  
  198.     rsxfpu_ver:
  199.         .long 109
  200.  
  201.     dpmi_esp:
  202.         .long 0
  203.     dpmi_ss:
  204.         .long 0
  205.     emu_esp:
  206.         .long 0xfff0
  207.     _debugged:
  208.         .long 0
  209.     _used_math:
  210.         .long 0
  211.  
  212.         .globl _process_npx
  213.     _process_npx:
  214.         .long _copro
  215.  
  216.     .lcomm _copro,172
  217.     .comm _info,92
  218.  
  219.